{extend name="extra@admin/content"}

{block name="content"}
<style>
.ibox-content{
  overflow-y: scroll;
  overflow-x: hidden;
  height: 500px;
}
</style>
<form onsubmit="return false;" action="__SELF__" data-auto="true" method="post" class='layui-form' style='padding-top:20px'>
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            {if $advert and isset($advert.title)}
            <input name="title" value='{$advert.title|default=""}'
                   required="required" title="请输入标题" maxlength="20" placeholder="请输入标题" class="layui-input ">
            {else}
            <input name="title" value='{$advert.title|default=""}' maxlength="20" required="required"
                   title="请输入标题" class="layui-input">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">副标题</label>
        <div class="layui-input-block">
            {if $advert and isset($advert.subtitle)}
            <input name="subtitle" value='{$advert.subtitle|default=""}'
                   required="required" title="请输入副标题" maxlength="20" placeholder="请输入副标题" class="layui-input ">
            {else}
            <input name="subtitle" value='{$advert.subtitle|default=""}' maxlength="20" required="required"
                   title="请输入副标题" class="layui-input">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">规格</label>
        <div class="layui-input-block">
            {if $advert and isset($advert.spec)}
            <input name="spec" value='{$advert.spec|default=""}'
                   required="required" title="请输入规格" maxlength="20" placeholder="请输入规格" class="layui-input ">
            {else}
            <input name="spec" value='{$advert.spec|default=""}' maxlength="20" required="required"
                   title="请输入规格" class="layui-input">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品简介</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入商品简介" maxlength="50" title="请输入商品简介不超过50个字符" class="layui-textarea" name="description">{$advert.description|default=""}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">推荐广告位</label>
        <div class="layui-input-block">
            <select name="adp_id" lay-verify="required" lay-filter="test" lay-search>
                <option value="">请选择广告位</option>
                {volist name='advert_position' id='v'}
                <option value="{$v.id}" {if condition="$advert['adp_id'] eq $v['id']"} selected {/if}>{$v.title}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">推荐商品</label>
        <div class="layui-input-block">
            <select name="goods_id" lay-verify="required" lay-filter="test" lay-search>
                <option value="">请选择推荐商品</option>
                {volist name='goods' id='v'}
                <option value="{$v.id}" {if condition="$advert['goods_id'] eq $v['id']"} selected {/if}>{$v.name}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上传图片</label>
            <div class="uploadimage"><input type="hidden" name="logo" {if $advert and !empty($advert.logo)} value="{$advert.logo}" {/if} /></div>
            <a data-file="one" data-field="logo" data-type="png,jpg,jpeg" data-uptype="qiniu" href="javascript:void(0)"
               class="uploadbutton">上传图片</a>
            {if $advert and !empty($advert.logo)}
            <script>
                $(function(){
                    var img = "{$advert.logo}";
                    require(['jquery'], function () {
                        $('[name="logo"]').parent().attr('data-tips-image', this.value).css('backgroundImage', 'url(' + img + ')');
                    });
                });
            </script>
            {/if}
            <script>
                require(['jquery'], function () {
                    $('[name="logo"]').on('change', function () {
                        $(this).parent().attr('data-tips-image', this.value).css('backgroundImage', 'url(' + this.value + ')');
                    });
                });
            </script>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否启用</label>
        <div class="layui-input-block">
            <input type="radio"  name="status" value="1"  title="启用" {if condition="$advert.status nheq 0"} checked {/if}>
            <input type="radio"  name="status" value="0"  title="禁用" {if condition="$advert.status heq 0"} checked {/if}>
        </div>
    </div>
    <div class="hr-line-dashed"></div>
    <div class="col-sm-4 col-sm-offset-2">
        {if $advert and isset($advert.id)}<input type='hidden' value='{$advert.id}' name='id'/>{/if}
        <input type="hidden" name="store_id" value="{$store_id}">
        <div class="layui-form-item text-center">
            <button class="layui-btn" type="submit">保存</button>
        </div>
    </div>
    <script type="text/javascript">
    layui.use('form', function(){
        var form = layui.form;      //只有执行了这一步，部分表单元素才会自动修饰成功
        form.render();
    });

    form.on('select(test)', function(data){

    });
</script>
</form>

{/block}